package net.linlan.plat.mbiz;


import net.linlan.commons.core.NumberUtils;
import net.linlan.commons.core.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Filename:ApiAdminConfig.java
 * Desc:管理会员用户常量配置类
 * @author Linlan
 * CreateTime:2017/11/2 14:06
 * @version 1.0
 * @since 1.0
 */
public abstract class ApiFieldConfig {

    /**
     * 返回字段的统一名称
     */
    public static final String RETURN_PARAMS = "data";
    /**
     * 返回字段的统一消息
     */
    public static final String RETURN_MSG= "msg";
    /**
     * 分页名称
     */
    public static final String FIELD_PAGE = "page";
    /**
     * 分页限制
     */
    public static final String FIELD_LIMIT = "limit";
    /**
     * 返回跨域回调信息
     */
    public static final String RETURN_HANDLER = "callback";
    /**
     * 携带变量的PARAMS
     */
    public static final String FIELD_PARAMS = "params";
    //匹配字段名称定义


    /**
     * 业务应用TYPE：ORGAN，USER，CONTENT，QUOTA
     */
    public static final String FIELD_TYPE_ORGAN = "organ";
    public static final String FIELD_TYPE_USER = "user";
    public static final String FIELD_TYPE_CONTENT = "content";
    public static final String FIELD_TYPE_QUOTA = "quota";
    public static final String FIELD_TYPE_ACTIVITY = "activity";
    public static final String FIELD_TYPE_THING = "thing";
    public static final String FIELD_TYPE_ADRESS = "adress";
    /**
     * 业务互动操作：view，comment，follow，collect，up，down，share等
     */
    public static final String FIELD_MUTUAL_VIEW = "view";
    public static final String FIELD_MUTUAL_COMMENT = "comment";
    public static final String FIELD_MUTUAL_FOLLOW = "follow";
    public static final String FIELD_MUTUAL_COLLECT = "collect";
    public static final String FIELD_MUTUAL_UP = "up";
    public static final String FIELD_MUTUAL_DOWN = "down";
    public static final String FIELD_MUTUAL_SHARE = "share";


    ////以下为日志内ServCode代码及名称转义对象，用于日志保存
    public static Map<Integer, String> servCodeMap = new HashMap<>();

    //日志信息定义区域
    public static final int SUCCESS = 0;
    public static final int ERROR = 1;
    public static final int RETURN_NONE = 201;

    public static final int UNAUTHORIZED = 401;
    public static final int FORBIDDEN = 403;
    public static final int NOT_FOUND = 404;
    public static final int INTERNAL_SERVER_ERROR = 500;

    public static final int TOKEN_ERROR = 700;
    public static final int INPUT_ERROR_CODE = 701;
    public static final int INPUT_ERROR_SOURCE = 702;
    public static final int ACCOUNT_NOT_EXIST = 703;
    public static final int CHANNEL_NOT_EXIST = 704;
    public static final int PARAMETER_ERROR = 711;
    public static final int NETWORK_ERROR = 712;
    public static final int THIRD_INFO_ERROR = 721;
    public static final int IP_WHITELIST_ERROR = 731;
    public static final int INFO_SEND_FAIL = 741;

    public static final int ERROR_USER_INFO = 1001;
    public static final int ERROR_USER_BY_SSO = 1002;
    public static final int ERROR_USER_BY_APP = 1003;
    public static final int ERROR_USER_BY_APP_STEP1 = 1004;
    public static final int ERROR_USER_BY_APP_STEP2 = 1005;
    public static final int ERROR_USER_BY_OUT = 1006;

    public static final int ERROR_USER_KEY = 1011;
    public static final int ERROR_USER_PASSWORD = 1012;
    public static final int ERROR_USER_REAL_NAME = 1013;
    public static final int ERROR_USER_NEED_LOGIN = 1014;
    public static final int ERROR_USER_NEED_FACE = 1015;
    public static final int ERROR_USER_IDENTITY = 1016;
    public static final int ERROR_USER_FACE = 1017;
    public static final int ERROR_USER_NEED_REG = 1018;

    public static final int ERROR_PARAMS_MATE = 1019;
    public static final int ERROR_RETURN_MANY = 1020;
    public static final int ERROR_NUMBER_FORMAT = 1021;
    public static final int ERROR_DATA_DUPLICATE = 1022;

    public static final int ERROR_ADDRESS_INVALID = 1101;
    public static final int ERROR_UPLOAD = 1102;
    public static final int ERROR_INPUT = 1103;
    public static final int ERROR_PASSWORD = 1104;

    public static final int ERROR_ENT = 1201;

    static {
        servCodeMap.put(SUCCESS, "系统访问正常");
        servCodeMap.put(ERROR, "系统访问异常");

        servCodeMap.put(UNAUTHORIZED, "TOKEN失效，请重新登录");
        servCodeMap.put(RETURN_NONE, "未查询到用户的数据");
        servCodeMap.put(FORBIDDEN, "页面禁止访问");
        servCodeMap.put(NOT_FOUND, "页面未找到");
        servCodeMap.put(INTERNAL_SERVER_ERROR, "未知错误");

        servCodeMap.put(TOKEN_ERROR, "TOKEN信息错误");
        servCodeMap.put(INPUT_ERROR_CODE, "信息传入有误(code)");
        servCodeMap.put(INPUT_ERROR_SOURCE, "信息传入有误(source)");
        servCodeMap.put(ACCOUNT_NOT_EXIST, "对接平台账户不存在");
        servCodeMap.put(CHANNEL_NOT_EXIST, "该栏目不存在");
        servCodeMap.put(PARAMETER_ERROR, "传递参数信息错误");
        servCodeMap.put(NETWORK_ERROR, "网络异常，请联系系统管理员");
        servCodeMap.put(THIRD_INFO_ERROR, "第三方数据信息验证失败");
        servCodeMap.put(IP_WHITELIST_ERROR, "白名单校验失败");
        servCodeMap.put(INFO_SEND_FAIL, "消息推送失败");


        servCodeMap.put(ERROR_USER_INFO, "用户数据信息验证失败");

        servCodeMap.put(ERROR_USER_BY_SSO, "SSO用户数据信息验证失败！");
        servCodeMap.put(ERROR_USER_BY_APP, "APP用户数据信息验证失败");
        servCodeMap.put(ERROR_USER_BY_APP_STEP1, "APP用户在调取第三方接口时失败");
        servCodeMap.put(ERROR_USER_BY_APP_STEP2, "APP用户数据调取第三方接口成功但是返回的数据不正确");
        servCodeMap.put(ERROR_USER_BY_OUT, "外部用户数据信息验证失败");

        servCodeMap.put(ERROR_USER_KEY, "用户关键信息错误");
        servCodeMap.put(ERROR_USER_PASSWORD, "用户密码信息错误");
        servCodeMap.put(ERROR_USER_REAL_NAME, "需要实名认证绑定");
        servCodeMap.put(ERROR_USER_NEED_LOGIN, "请用户重新登录");
        servCodeMap.put(ERROR_USER_NEED_FACE, "需要人脸识别二次认证");
        servCodeMap.put(ERROR_USER_IDENTITY, "认证失败，请重新认证");
        servCodeMap.put(ERROR_USER_FACE, "人脸识别信息与系统不一致");
        servCodeMap.put(ERROR_USER_NEED_REG, "用户信息未注册，请注册");

        servCodeMap.put(ERROR_PARAMS_MATE, "传参不匹配！");
        servCodeMap.put(ERROR_RETURN_MANY, "查询出多条数据！");
        servCodeMap.put(ERROR_NUMBER_FORMAT, "数字格式转换异常");
        servCodeMap.put(ERROR_DATA_DUPLICATE, "数据重复");

        servCodeMap.put(ERROR_ADDRESS_INVALID, "无效访问地址");
        servCodeMap.put(ERROR_UPLOAD, "上传出现错误，请联系管理员");
        servCodeMap.put(ERROR_INPUT, "填写信息错误，请检查");
        servCodeMap.put(ERROR_PASSWORD, "密码必须为大小写字母,数字,特殊字符中的至少3种且8位-20位之内");
        servCodeMap.put(ERROR_ENT, "企业关键信息错误");
    }

    public static String valueOf(final Integer code) {
        if (NumberUtils.isBlankChar(code)) {
            throw new NullPointerException("Code is null or empty");
        }
        String info = servCodeMap.get(code);
        if (StringUtils.isBlank(info)) {
            return "No servCode const " + code;
        }
        return info;
    }


}
